package com.example.booksdeal.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.booksdeal.BmobDBO.Comment;
import com.example.booksdeal.R;

import java.util.List;

public class MyAdapter extends BaseAdapter {
    private Context context;
    private List<Comment> list;

    public MyAdapter(Context context,List<Comment> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            String nickname,comment,time;
            nickname = list.get(i).getUser().getNickname();
            comment = list.get(i).getComment();
            time = list.get(i).getCreatedAt();
            LayoutInflater inflater = LayoutInflater.from(context);
            view = inflater.inflate(R.layout.activity_comment_item,null);
            TextView nicheng = view.findViewById(R.id.nicheng);
            TextView commenttv = view.findViewById(R.id.commenttv);
            TextView time1 = view.findViewById(R.id.time);
            nicheng.setText(nickname);
            commenttv.setText(comment);
            time1.setText(time);
        }
        return view;
    }
}
